<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Home extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->helper('form', 'url');
        $this->load->library('session', 'form_validation', 'table');
        $this->load->model('all');
    }

    function login() {
        $akses = $this->session->userdata('log_in');
        $hak = $this->session->userdata('akses');
        if (!isset($akses) || $akses != TRUE && $hak != 'admin') {
            redirect('login');
        }
    }

    function index() {
        $this->login();
        $this->load->view('tema/head');
        $this->load->view('tema/atas');
        $this->load->view('tema/thumbnail');
        $this->load->view('tema/end');
    }

    function profile() {
        $this->login();
        $username = $this->session->userdata('username');
        $pro['profil'] = $this->all->profile($username);
        $this->load->view('tema/head');
        $this->load->view('tema/atas');
        $this->load->view('siswa/profile', $pro);
        $this->load->view('tema/end');
    }

    function upd_pass() {
        $this->login();
        $data = array(
            'username' => $this->session->userdata('username'),
            'password' => $this->encrypt->sha1($this->input->post('password'))
        );
        $this->all->upd_pass($data);
        redirect('home/logout');
    }

    function rekap_nilai() {
        $this->login();
        $this->load->view('tema/head');
        $this->load->view('tema/atas');
        $this->load->view('siswa/rekap_nilai');
        $this->load->view('tema/end');
    }

    function user() {
        $this->login();
        $data['hasil'] = $this->all->user();
        $this->load->view('tema/head');
        $this->load->view('tema/atas');
        $this->load->view('siswa/user', $data);
        $this->load->view('tema/end');
    }

    function add_user() {
        $user = array(
            'username' => $this->input->post('username'),
            'password' => $this->encrypt->sha1($this->input->post('pass')),
            'type' => $this->input->post('akses')
        );
        $this->all->add_user($user);
        redirect('home/user');
    }

    function del_user() {
        $id = $this->uri->segment(3);
        $this->all->del_user($id);
        redirect('home/user');
    }

    function ubah_user() {
        $id = $this->uri->segment(3);
        $ubah['ub'] = $this->all->ubah_user($id);
        $ubah['user'] = $this->all->user();
        $this->load->view('siswa/user_update', $ubah);
    }

    function update_user() {
        $update = array(
            'username' => $this->input->post('username'),
            'type' => $this->input->post('akses'),
            'status' => $this->input->post('status')
        );
        $this->all->update_user($update);
        redirect('home/user');
    }

    function nilai() {
        $this->login();
        $this->load->view('tema/head');
        $this->load->view('tema/atas');
        $this->load->view('siswa/nilai');
        $this->load->view('tema/end');
    }

    function success() {
        $this->login();
        $this->load->view('siswa/success');
    }

    function logout() {
        $this->session->sess_destroy();
        redirect(); //fungsinya dia menuju ke basu_url
    }

}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
